#include "systemfile.h"

systemFile::systemFile()
{
    QString fileName=QString("%1/settings.ini").arg(QDir::currentPath());
        this->devSetting = new QSettings(fileName,QSettings::IniFormat);
        if(QFile::exists(fileName) == false)
        {
            this->resetSetting();
        }
        this->readSetting();
    }
    //读取系统设置
    bool systemFile::readSetting()
    {

        //this->devSetting->setIniCodec(QTextCodec::codecForName("UTF-8"));
        this->devSetting->beginGroup("SERVER");
        this->serverIp = this->devSetting->value("serverIp").toString();
        this->userName = this->devSetting->value("userName").toString();
        this->passWord = this->devSetting->value("passWord").toString();
        this->databaseName = this->devSetting->value("databaseName").toString();
        this->serverPort = this->devSetting->value("serverPort").toString();
        this->devSetting->endGroup();

        this->devSetting->beginGroup("TCP");
        this->devPort = this->devSetting->value("devPort").toString();
        this->localIp = this->devSetting->value("localIp").toString();
        this->localPort = this->devSetting->value("localPort").toString();
        this->devSetting->endGroup();


        qDebug()<<"****************************************";
        qDebug()<<"******SERVER********";
        qDebug()<<"serverIp*****"<<this->serverIp;
        qDebug()<<"userName*****"<<this->userName;
        qDebug()<<"passWord*****"<<this->passWord;
        qDebug()<<"datebaseName*"<<this->databaseName;
        qDebug()<<"serverPort***"<<this->serverPort;
        qDebug()<<"****************************************";
        qDebug()<<"******TCP********";
        qDebug()<<"devPort*******"<<this->devPort;
        qDebug()<<"localIp*******"<<this->localIp;
        qDebug()<<"localPort****"<<this->localPort;
        qDebug()<<"****************************************";
        return true;
    }

    bool systemFile::resetSetting()
    {
        QString fileName=QString("%1/settings.ini").arg(QDir::currentPath());
        QString fileInfo;
        QFile myfile(fileName);
        qDebug() << "*********************************";
        qDebug() << "reset setting";
        qDebug() << "*********************************";
        myfile.open(QIODevice::WriteOnly);
        //
        fileInfo.append("[SERVER]\r\n");
        fileInfo.append("serverIp = 192.168.10.9\r\n");
        fileInfo.append("userName = copy\r\n");
        fileInfo.append("passWord = 6269768\r\n");
        fileInfo.append("databaseName = pn\r\n");
        fileInfo.append("serverPort = 3306\r\n");
        //
        fileInfo.append("[TCP]\r\n");
        fileInfo.append("devPort = 6666\r\n");
        fileInfo.append("localIp = 192.168.10.9\r\n");
        fileInfo.append("localPort = 3556\r\n");
        myfile.write(fileInfo.toLocal8Bit());
        myfile.close();
        qDebug()<<"serverIp*****"<<"192.168.10.9";
        qDebug()<<"userName*****"<<"copy";
        qDebug()<<"passWord*****"<<"6269768";
        qDebug()<<"datebaseName*"<<"pn";
        qDebug()<<"serverPort***"<<"3306";
        qDebug()<<"devPort******"<<"6666";
        qDebug()<<"localIp****"<<"192.168.10.9";
        qDebug()<<"localPort****"<<"3556";
        return true;
    }


